package com.yzy.dao;

import com.yzy.entity.Books;
import com.yzy.entity.Doctors;
import com.yzy.entity.Patients;
import com.yzy.utils.Utils;

import javax.servlet.ServletContext;
import java.awt.print.Book;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class BookDao {
    private Utils util = new Utils();

    public int addbook(String pphone, Integer doctorId,String mydate){

        String sql = "insert into book(pphone,did,time) values(?,?,?) ";
        int result = 0;
        try {
            PreparedStatement ps =util.createStatement(sql);
            ps.setString(1,pphone);
            ps.setInt(2,doctorId);
            ps.setString(3,mydate);
            result = ps.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            util.close();
        }return result;
    }
    //预约查询
    public List bookfind(){

        String sql = "select * from book";
        PreparedStatement ps =util.createStatement(sql);
        List<Books> booklist=new ArrayList<>();
        ResultSet rs =null;



        try {
            rs = ps.executeQuery();
            while (rs.next()){
                String pphone=rs.getString("pphone");
                String did=rs.getString("did");
                String time=rs.getString("time");
                String state=rs.getString("state");
                Books books = new Books(pphone,did,time,state);
                booklist.add(books);

            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            util.close();
        }return booklist;

    }
    /*public String pnamefind(){
        String pphone;
        String sql1="select pname from patient where pphone=?";
        PreparedStatement ps1=util.createStatement(sql1);
        ResultSet rs1=null;
        try {
            ps1.setString(1,pphone);
            rs1 =ps1.executeQuery();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {

            util.close(rs1);
            util.close();
        }return pphone;

    }*/
}
